Improve configuration load errors
authorAlex Crichton <alex@alexcrichton.com>
Wed, 3 May 2017 16:57:37 +0000 (09:57 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 3 May 2017 17:00:30 +0000 (10:00 -0700)
Add some more context information on the backtrace

src/cargo/util/config.rs
tests/bad-config.rs

index 762bc79de757ec70cdb6bd5b1f4f05ac5e4b0601..aa27fa0436c504d415f8e5c7016bdc2e295bb6da 100644 (file)
@@ -394,7 +394,10 @@ impl Config {
 
         walk_tree(&self.cwd, |mut file, path| {
             let mut contents = String::new();
-            file.read_to_string(&mut contents)?;
+            file.read_to_string(&mut contents).chain_error(|| {
+                human(format!("failed to read configuration file `{}`",
+                              path.display()))
+            })?;
             let toml = cargo_toml::parse(&contents,
                                          &path,
                                          self).chain_error(|| {
@@ -405,7 +408,10 @@ impl Config {
                 human(format!("failed to load TOML configuration from `{}`",
                               path.display()))
             })?;
-            cfg.merge(value)?;
+            cfg.merge(value).chain_error(|| {
+                human(format!("failed to merge configuration at `{}`",
+                              path.display()))
+            })?;
             Ok(())
         }).chain_error(|| human("Couldn't load Cargo configuration"))?;
 
index 8ceb2fdaf860bdcfff2d1792df33fbb8a5ec5431..f82495cc2ee63ccac86189764a029fe265e10baa 100644 (file)
@@ -120,6 +120,9 @@ fn bad5() {
 Caused by:
   Couldn't load Cargo configuration
 
+Caused by:
+  failed to merge configuration at `[..]`
+
 Caused by:
   failed to merge key `foo` between files:
   file 1: [..]foo[..]foo[..]config